package fiszki.namespace;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FiszkaTasksAdapter extends ArrayAdapter<FiszkaTasks> {
    private Activity context;
    private List<FiszkaTasks> tasks;
    
    public FiszkaTasksAdapter(Activity context, List<FiszkaTasks> tasks) {
        super(context, R.layout.lv_fiszka_item, tasks);
        this.context = context;
        this.tasks = tasks;
    }
 
    static class ViewHolder {
        public TextView tvQuestion;
        public TextView tvAnswer;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View rowView = convertView;
        
        if(rowView == null) {
            LayoutInflater layoutInflater = context.getLayoutInflater();
            rowView = layoutInflater.inflate(R.layout.lv_fiszka_item, null, true);
            viewHolder = new ViewHolder();
            viewHolder.tvQuestion = (TextView) rowView.findViewById(R.id.tvQuestion);
            viewHolder.tvAnswer = (TextView) rowView.findViewById(R.id.tvAnswer);
            rowView.setTag(viewHolder);
        } 
        else {
            viewHolder = (ViewHolder) rowView.getTag();
        }
        
        FiszkaTasks task = tasks.get(position);
        viewHolder.tvQuestion.setText(task.getQuestion());
        viewHolder.tvAnswer.setText(task.getAnswer());
        
        return rowView;
    }
}
